package com.azhon.entry.utils;

import com.azhon.appupdate.utils.ApkUtil;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;
import ohos.bundle.ApplicationInfo;
import ohos.bundle.BundleInfo;
import ohos.bundle.IBundleManager;
import ohos.rpc.RemoteException;
import org.junit.Test;

import static org.junit.Assert.*;

public class ApkUtilTest {

    private final Context mContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();

    @Test
    public void getVersionCode() {
        int num = ApkUtil.getVersionCode(mContext);
        assertEquals(1000000, num);
    }

    @Test
    public void getVersionName() throws RemoteException {
        String name = ApkUtil.getVersionName(mContext);
        IBundleManager packageManager = mContext.getBundleManager();
        BundleInfo packageInfo = packageManager.getBundleInfo(mContext.getBundleName(), 0);
        assertEquals(packageInfo.getVersionName(), name);
    }

    @Test
    public void getAppName() throws RemoteException {
        String name = ApkUtil.getAppName(mContext);
        IBundleManager packageManager = mContext.getBundleManager();
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(mContext.getBundleName(), 0, 0);
        assertEquals(applicationInfo.getLabel(), name);
    }
}